<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="机构名称">
              <j-select-depart
                v-model="queryParam.officeId"
                :trigger-change="true"
                customReturnField="id"
                :multi="false"
              ></j-select-depart>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="年度">
              <a-date-picker
                mode="year"
                placeholder="请选择年份"
                format="YYYY"
                value-format="yyyy-MM-dd"
                v-model="queryParam.year"
                :open="yearPickShow"
                style="width: 100%"
                @panelChange="handlePanelChange"
                @openChange="handleOpenChange"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="季度">
              <j-dict-select-tag
                style="width: 100%"
                v-model="queryParam.quarter"
                placeholder="请选择"
                dict-code="sys_quarter"
              />
            </a-form-item>
          </a-col>
          <!--          <a-col :md="6" :sm="8">-->
          <!--            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
          <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
          <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
          <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
          <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
          <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
          <!--              </a>-->
          <!--            </span>-->
          <!--          </a-col>-->
        </a-row>
      </a-form>
    </div>
    <!-- <div style="height: 300px; overflow: visible;margin-bottom:10px">
      <Checkquestion v-if="questionData.length > 0" :dataScoure="questionData" />
         <a-empty v-else/>
    </div> -->
    <!-- 操作按钮区域 -->
    <!--    <div class="table-operator">-->
    <!--      <a-button @click="handleAdd('临时审计计划制定-新增')" type="primary" icon="plus">新增</a-button>-->
    <!--    </div>-->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="departName" slot-scope="departName">
          <div style="width: 100%; height: 45px; overflow-x: hidden; overflow-y: auto">{{ departName }}</div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleCheck(record, '审计发现问题分类统计表(季报)')">查看</a>
          <a-divider type="vertical" />
          <a @click="handleDownload(record)">下载</a>
          <!--          <a-divider type="vertical"/>-->
          <!--          <a-dropdown>-->
          <!--            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>-->
          <!--            <a-menu slot="overlay">-->
          <!--                <a-menu-item>-->
          <!--                  <a @click="handleEdit(record,'临时审计计划制定-编辑')">编辑</a>-->
          <!--              </a-menu-item>-->
          <!--              <a-menu-item>-->
          <!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
          <!--                  <a>删除</a>-->
          <!--                </a-popconfirm>-->
          <!--              </a-menu-item>-->
          <!--            </a-menu>-->
          <!--          </a-dropdown>-->
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <CheckAndEditModel ref="modalForm"></CheckAndEditModel>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CheckAndEditModel from './CheckAndEditModel'
import { httpAction, getAction } from '@/api/manage'
import moment from 'moment'
import 'moment/locale/zh-cn'
import columns from './indexColumns'
import Checkquestion from '@/views/sj/sjxxzhbb/fxwthzbb/Checkquestion'
import { getApi } from '@/utils/neiORwai'
export default {
  name: '发现问题汇总报表',
  mixins: [JeecgListMixin],
  components: {
    CheckAndEditModel,
    Checkquestion,
  },
  data() {
    return {
      queryParam: {
        officeId: '',
        year: '',
        quarter: '',
      },
      superParam: {
        type: '2',
      },
      // 表头
      columns: columns(this),
      url: {
        list: '/sjxxzhgl/sjProjectReport/queryProjectReportInfo',
        downLoad: '/sjxxzhgl/sjProjectReport/exportProjectReportInfo',
        question: '/sjxxzhgl/sjProjectReport/getChart2',
      },
      yearPickShow: false,
      questionData: [],
    }
  },
  beforeMount() {
    // this.getEquestionData()
  },
  methods: {
    searchQuery() {
      this.loadData(1)
      this.getEquestionData()
    },
    searchReset() {
      this.queryParam = this.$options.data().queryParam
      this.loadData(1)
      this.getEquestionData()
    },
    // 弹出日历和关闭日历的回调
    handleOpenChange(status) {
      this.yearPickShow = status
      if(this.queryParam.year){
        this.queryParam.year = moment(this.queryParam.year.slice(0, 4)).format('YYYY')
      }
    },
    handleDownload(record) {
      getAction(this.url.downLoad, { id: record.id, type: '2' })
        .then((res) => {
          if (res.success && res.result) {
            this.$message.success('正在下载，请稍等！')
            let url = `${getApi() || window._CONFIG['domianURL']}/sys/common/static${res.result}`
            // let url = `${window._CONFIG['domianURL']}/sys/common/static${res.result}`
            window.open(url, '_blank')
          } else {
          }
        })
        .finally(() => {})
    },
    moment,
    // 得到年份选择器的值
    handlePanelChange(value) {
      this.yearPickShow = false
      this.queryParam.year = moment(value).format('YYYY')
    },
    getEquestionData() {
      getAction(this.url.question, { year: this.queryParam.year }).then((res) => {
        if (res.success) {
          this.questionData = res.result || res.record.result
        } else {
          this.$message.warning(res.message)
        }
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>